package com.hospital.hospitalserver.exception;

import com.hospital.hospitalserver.util.Response;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 */
@RestControllerAdvice(basePackages = "com.hospital.hospitalserver.controller")
public class GlobalExceptionHandler {
    /**
     * 处理业务异常
     * */
    @ExceptionHandler(CustomException.class)
    public Response handleCustomException(CustomException e){
        return Response.error(e.getCode(),e.getMsg());
    }

    /**
     * 处理系统异常
     * */
    @ExceptionHandler(Exception.class)
    public Response handleException(Exception e){
        return Response.error(e.toString());
    }
}
